#include "board.h"
#include "stdio.h"
#include "dht11.h"
#include "bsp_sht30.h"
#include "bsp_VL53L0X.h"

extern VL53L0X_Dev_t vl53l0x_dev;//设备I2C数据参数
int main(void)
{
    nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);  // 优先级分组
    board_init();
    bsp_uart_init();

    DHT11_GPIO_Init();          //DHT11引脚初始化
    SHT30_GPIO_Init();          //SHT30引脚初始化

    //VL53L0X
    uint8_t mode = 0;//0：默认;1:高精度;2:长距离;3:高速
    VL53L0X_Error Status=VL53L0X_ERROR_NONE;//工作状态
    nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);   // 优先级分组
    while(vl53l0x_init(&vl53l0x_dev))//vl53l0x初始化
    {
        printf("VL53L0X Error!!!\n\r");
        delay_ms(500);
    }
    printf("VL53L0X OK\r\n");

    while(vl53l0x_set_mode(&vl53l0x_dev,mode))//配置测量模式
    {
        printf("Mode Set Error\r\n");
        delay_ms(500);
    }

    delay_ms(1000);
    printf("start\r\n");
    while(1)
    {
        //读取模块数据
        DHT11_Read_Data();
        //显示读取后的温度数据
        printf("temperature = %.2f\r\n", Get_temperature() );
        //显示读取后的湿度数据
        printf("humidity = %.2f\r\n", Get_humidity() );

        SHT30_Read(0xe000); //SHT30读取数据
        
        //显示读取后的距离
        if(Status==VL53L0X_ERROR_NONE)
        {
            //执行单次测距并获取测距测量数据
            Status = VL53L0X_PerformSingleRangingMeasurement(&vl53l0x_dev, &vl53l0x_data);
            printf("d: %4imm\r\n",vl53l0x_data.RangeMilliMeter);//打印测量距离
        }
        else
        {
        printf("error\r\n");
        }
        delay_ms(1000);
    }
}